import Request from 'utils/request';

import OrderRecord from 'models/financeMgr/orderRecord';
import RefundOrder from 'models/financeMgr/refundOrder';

export default class OrderMgrApi {
  static getOrderData(search, pagination) {
    const apiName = 'api/viewordergoods/wechatpay/queryOrderGoods';

    let postData = search.getObject(pagination);

    return Request.post(apiName, postData).then(res => {
      let orderList = res.data;
      orderList = _.map(orderList, order => {
        order = new OrderRecord(order);
        return order;
      });

      pagination.totalCount = res.rows;
      return orderList;
    });
  }

  static getRefundOrderData(search, pagination) {
    const apiName = 'api/viewordergoods/wechatpay/orderRefuseInfo';

    let postData = search.getObject(pagination);

    return Request.post(apiName, postData).then(res => {
      let orderList = res.data;
      orderList = _.map(orderList, order => {
        order = new RefundOrder(order);
        return order;
      });

      pagination.totalCount = res.rows;
      return orderList;
    });
  }

  static updateRefundOrderStatus(postData) {
    const apiName = 'api/viewordergoods/wechatpay/orderRefuseAudit';

    return Request.post(apiName, postData).then(res => {
      return res.msg;
    });
  }
}
